﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL;
using System.Web.SessionState;
namespace WeChat.Ajax
{
    /// <summary>
    /// BinDing 的摘要说明
    /// </summary>
    public class BinDing : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            string RNM = "";
            //获取选中类型
            string BinDingType = context.Request.Form["BinDingType"];
            //获取修改卡号
            string rfkh = context.Request.Form["cardid"];
            //获取登录密码
            string password = context.Request.Form["qpassword"];
            //获取Opid
            string Opid = context.Session["openid"] == null ? "" : context.Session["openid"].ToString();

            //返回状态
            switch (BinDingType)
            {
                case "BinDingrfkh":
                    int rfnum = BindIdBLL.BinDingkh(rfkh);
                    int judgePassword = BindIdBLL.judgePassword(password, Opid);
                    if (judgePassword == 0)
                    {
                        RNM = "0";
                    }
                    else if (rfnum == 0)
                    {
                        //绑定卡号	
                        int BinDingNum = BindIdBLL.BinDingrfkhs(rfkh, password, Opid);
                        //修改卡状态
                        int Updaterfkh = BindIdBLL.Updaterfkh(password, Opid);
                        //绑定IdBinDing
                        int IdBanDin = BindIdBLL.IdBanDin(rfkh, Opid);
                        RNM = "1";
                    }
                    else
                    {
                        RNM = "2";
                    }

                    break;
                case "Displaykh":
                    int BinDingRfkh = BindIdBLL.BinDingRfkh(Opid);
                    if (BinDingRfkh == 0)
                    {
                        RNM = "0";
                    }
                    else if (BinDingRfkh == 1)
                    {
                        RNM = "1";
                    }
                    break;
                default:
                    break;
            }
            context.Response.Write(RNM);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}